/* Copyright (c) 2004-2024 peigen.info. All rights reserved. */

package info.peigen.hotpot.business.account.manage.convertor;

import cn.hutool.core.bean.BeanUtil;
import info.peigen.hotpot.business.account.core.domain.account.Account;
import info.peigen.hotpot.business.account.core.repository.entity.AccountEntity;
import info.peigen.hotpot.business.account.manage.form.AccountManageCreateForm;
import info.peigen.hotpot.business.account.manage.form.AccountManageEditForm;
import info.peigen.hotpot.business.account.manage.form.AccountManageSearchForm;
import info.peigen.hotpot.business.account.manage.info.AccountManageInfo;
import info.peigen.hotpot.common.core.util.IdUtil;
import lombok.extern.slf4j.Slf4j;

/**
 * <b>(AccountManageConvertor)</b>
 * 管理后台领域对象 "账户" 转换器
 *
 * @author Peigen
 * @version 1.0.0
 * @since 2023-08-29
 */
@SuppressWarnings("unused")
@Slf4j
public class AccountManageConvertor {
    // ConvertToEntity
    public static AccountEntity convertToEntity(Account domain) {
        return BeanUtil.copyProperties(domain, AccountEntity.class);
    }

    public static AccountEntity convertToEntity(AccountManageInfo info) {
        return BeanUtil.copyProperties(info, AccountEntity.class);
    }

    public static AccountEntity convertToEntity(AccountManageSearchForm form) {
        return BeanUtil.copyProperties(form, AccountEntity.class);
    }

    public static AccountEntity convertToEntity(AccountManageCreateForm form) {
        if (form.getAccountId() == null) {
            form.setAccountId(IdUtil.id());
        }
        return BeanUtil.copyProperties(form, AccountEntity.class);
    }

    public static AccountEntity convertToEntity(AccountManageEditForm form) {
        return BeanUtil.copyProperties(form, AccountEntity.class);
    }

    // ConvertToDomain
    public static Account convertToDomain(AccountEntity entity) {
        return BeanUtil.copyProperties(entity, Account.class);
    }

    public static Account convertToDomain(AccountManageInfo info) {
        return BeanUtil.copyProperties(info, Account.class);
    }

    public static Account convertToDomain(AccountManageSearchForm form) {
        return BeanUtil.copyProperties(form, Account.class);
    }

    public static Account convertToDomain(AccountManageCreateForm form) {
        if (form.getAccountId() == null) {
            form.setAccountId(IdUtil.id());
        }
        return BeanUtil.copyProperties(form, Account.class);
    }

    public static Account convertToDomain(AccountManageEditForm form) {
        return BeanUtil.copyProperties(form, Account.class);
    }

    // convertToInfo
    public static AccountManageInfo convertToInfo(Account domain) {
        return BeanUtil.copyProperties(domain, AccountManageInfo.class);
    }

    public static AccountManageInfo convertToInfo(AccountEntity entity) {
        return BeanUtil.copyProperties(entity, AccountManageInfo.class);
    }

    public static AccountManageInfo convertToInfo(AccountManageSearchForm form) {
        return BeanUtil.copyProperties(form, AccountManageInfo.class);
    }

    public static AccountManageInfo convertToInfo(AccountManageCreateForm form) {
        if (form.getAccountId() == null) {
            form.setAccountId(IdUtil.id());
        }
        return BeanUtil.copyProperties(form, AccountManageInfo.class);
    }

    public static AccountManageInfo convertToInfo(AccountManageEditForm form) {
        return BeanUtil.copyProperties(form, AccountManageInfo.class);
    }
}